/**
 *
 * Created by hc on 2016/11/27.
 */
(function (main) {
    var process = {};


    //注册监听事件
    process.registerListener = function () {
        
    };
    //填充表格
    process.fillTable = function (result) {
        lst_logs = result;

        var html = '';
        if (lst_logs.length > 0) {
            for (var index in lst_logs) {
                var operation_log = lst_logs[index];
                var tr_html = "<tr>";
                tr_html += "<td>" + operation_log.operation_type + "<br /></td>";
                tr_html += "<td  style='width: 450px;'>" + operation_log.content + "</td>"
                tr_html += "<td>" + operation_log.operator + "</td>"
                tr_html += "<td>" + operation_log.operate_time + "</td>"
                tr_html += "</tr>";
                html += tr_html;
            }
        } else {
            html = '<td style="text-align:center" colspan="10">没查到数据</td>'
        }
        $('#search_result tbody').html('');
        $('#search_result tbody').html(html);
    };
    //加载数据
    process.loadData = function () {
        var id = $("#id").val();
        if (id) {
            $.ajax({
                url: '/AjaxService/center/field/findoperationlog',
                data: {'line_id': id},
                dataType: 'json',
                type: 'post',
                async: false,
                success: function (resp) {
                    process.fillTable(resp.Result);
                }
            });

            //设置产品型号不可编辑
            $('input[name="product_type"]').attr("readonly","readonly");
        }
    };

    //初始化图片
    process.initPicture = function(){
        $("input[is-img='true']").each(function(index , item){
            //如果图片有值那么创建<img>标签
            var value = $(item).val();
            if(value){
                if (value.indexOf('pdf') > 0) {
                    $("[target='" +  $(item).attr('name') +"']").append("<img class='uploaded-img'  src='" + $('#server_name').val() + "/Public/Uploads/pdf.png'>");
                } else {
                    $("[target='" +  $(item).attr('name') +"']").append("<img class='uploaded-img'  src='" + $('#server_name').val() + value + "'>");
                }
                var filename = $("[target='" +  $(item).attr('name') +"']").siblings('.image-title').text();
                //添加下载链接
                $("[target='" +  $(item).attr('name') +"']").siblings('.image-title').append("<a class='download-link' href='/process/download?path="+value+"&filename="+filename+"'>下载</a>");

            }
        });

    }

    //
    main.process = process;
    main.process.loadData();
    main.process.initPicture();
    main.process.registerListener();

})(window);